@using k8s.Models
@inherits BlazorApp.Pages.Common.PageBase

@if (PodSpec != null)
{
    <Divider Orientation="left" Style="font-weight:bold">
        @L["Container"] <span style="color:#DCDCDC">(@Count())</span>
    </Divider>
    <ContainerSpecView Containers="@PodSpec.Containers" OnPortForward="OnPortForwardBtnClick" ShowPortForwardBtn="ShowPortForwardBtn"
                       Type="Main">
    </ContainerSpecView>
    <ContainerSpecView Containers="@PodSpec.InitContainers"
                       Type="Init">
    </ContainerSpecView>
    <EphemeralContainerSpecView Containers="@PodSpec.EphemeralContainers"
                                Type="Ephemeral">
    </EphemeralContainerSpecView>
}

@code {

    [Parameter]
    public V1PodSpec PodSpec { get; set; }

    [Parameter]
    public bool ShowPortForwardBtn { get; set; }

    [Parameter]
    public EventCallback<int> OnPortForward { get; set; }

    private async Task OnPortForwardBtnClick(int port)
    {
        await OnPortForward.InvokeAsync(port);
    }


    private int Count()
    {
        if (PodSpec == null)
        {
            return 0;
        }

        var count = 0;

        if (PodSpec.Containers != null)
        {
            count += PodSpec.Containers.Count;
        }

        if (PodSpec.InitContainers != null)
        {
            count += PodSpec.InitContainers.Count;
        }

        if (PodSpec.EphemeralContainers != null)
        {
            count += PodSpec.EphemeralContainers.Count;
        }

        return count;
    }

}
